﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TCHSHue.BLL;

namespace TCHSHue.Modules.IndexControl.GioiThieu
{
    public partial class ctrGioiThieu : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var id = Request.QueryString["id"];
                var idBaiViet = Request.QueryString["idBaiViet"];
                if (id == "cocautochuc")
                    NapBaiViet(Hang.COCAUTOCHUC);
                else if (id == "nhiemvu")
                    NapBaiViet(Hang.CHUCNANGNHIEMVU);
            }
        }

        private void NapBaiViet(int maTheLoai)
        {
            var ls = BaiVietBLL.getListTheoTrang(maTheLoai, 1, 1);
            if (ls != null && ls.Count >= 1)
            {
                var bv = BaiVietBLL.getBaiViet(ls[0].MaBaiViet.ToString());
                if (bv != null)
                {
                    lbChuDe.Text = Server.HtmlDecode(bv.chuDe);
                    txtNoiDung.Text = Server.HtmlDecode(bv.noiDung);
                }
            }
        }

        private void NapBaiViet(string maBaiViet)
        {

            if (!string.IsNullOrEmpty(maBaiViet))
            {
                var bv = BaiVietBLL.getBaiViet(maBaiViet);
                if (bv != null)
                {
                    lbChuDe.Text = Server.HtmlDecode(bv.chuDe);
                    txtNoiDung.Text = Server.HtmlDecode(bv.noiDung);
                }
            }
        }
    }
}